package com.yuanluludev.gaode.utils

import android.os.Build
import com.yuanluludev.lib_utils.util.PermissionUtils

object LocPermissionUtils {

    enum class Times {
        FIRST,
        SECOND
    }

    /**
     * 获取定位需要的权限 Android 10之前和之后
     * times 代表第几次所需要的权限  Android10之后需要两次分别申请
     */
    internal fun getLocPermission(times: Times = Times.FIRST): Array<String> {
        //小于Android 10
        return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
            LocConstants.normalLocPermissions
        } else {//大于Android 10
            if (LocUtils.isBackgroundLoc) { //后台
                if (times == Times.FIRST) {
                    LocConstants.normalLocPermissions
                } else {
                    LocConstants.backgroundLocPermissions
                }
            } else { //前台
                LocConstants.normalLocPermissions
            }
        }
    }

    /**
     * 仅用于 onResume()
     * 判断基本的定位权限是否开启
     */
    internal fun isLocPermissionGranted(): Boolean {
        return PermissionUtils.isGranted(*LocConstants.normalLocPermissions)
    }

}